
import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class ${cmdName}${type}Cmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        ${cmdName}BO reqData = super.getData(sign, ${cmdName}BO.class);

        <#if type == "Get">
        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
            .addParam("id", reqData.getId())
            .setReturnStruct(sign.getReturnStruct());
        ${cmdName}BO respData = this.${cmdName}Service.get(paramsBuilder.build());
        respSign.setSource(super.getSource(respData));
        </#if>
        <#if type == "List">
        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
            .setReturnStruct(sign.getReturnStruct());
        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<${cmdName}BO> respDataList = this.${cmdName}Service.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));
        </#if>
        <#if type == "Post">
        this.${cmdName}Service.post(reqData);
        </#if>
        <#if type == "Patch">
        this.${cmdName}Service.update(reqData);
        </#if>
        <#if type == "Del">
        ${cmdName}BO del${cmdName}BO = new ${cmdName}BO();
        del${cmdName}BO.setId(reqData.getId());
        this.${cmdName}Service.del(del${cmdName}BO);
        </#if>

        return respSign;
    }

    @Override
    public String getCmdCode() {
    <#if type == "Get">
        return ${cmdName}CmdCode.${cmdCode}_GET;
    </#if>
    <#if type == "List">
        return ${cmdName}CmdCode.${cmdCode}_LIST;
    </#if>
    <#if type == "Post">
        return ${cmdName}CmdCode.${cmdCode}_POST;
    </#if>
    <#if type == "Patch">
        return ${cmdName}CmdCode.${cmdCode}_PATCH;
    </#if>
    <#if type == "Del">
        return ${cmdName}CmdCode.${cmdCode}_DEL;
    </#if>
    }

    @Autowired
    private I${cmdName}Service ${cmdName}Service;
}